package cn.com.guage.dtm.stat.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.stat.domain.StatDataCover;
import cn.com.guage.dtm.stat.service.IStatDataCoverService;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 覆盖度分析Controller
 * 
 * @author yangdechao
 * @date 2021-06-22
 */
@Controller
@RequestMapping("/stat/cover")
public class StatDataCoverController extends BaseController
{
    private String prefix = "stat/cover";

    @Autowired
    private IStatDataCoverService statDataCoverService;

    @RequiresPermissions("stat:cover:view")
    @GetMapping()
    public String cover()
    {
        return prefix + "/cover";
    }

    /**
     * 查询覆盖度分析列表
     */
    @RequiresPermissions("stat:cover:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatDataCover statDataCover)
    {
        startPage();
        List<StatDataCover> list = statDataCoverService.selectStatDataCoverList(statDataCover);
        return getDataTable(list);
    }

    /**
     * 导出覆盖度分析列表
     */
    @RequiresPermissions("stat:cover:export")
    @Log(title = "覆盖度分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatDataCover statDataCover)
    {
        List<StatDataCover> list = statDataCoverService.selectStatDataCoverList(statDataCover);
        ExcelUtil<StatDataCover> util = new ExcelUtil<StatDataCover>(StatDataCover.class);
        return util.exportExcel(list, "覆盖度分析数据");
    }

    /**
     * 新增覆盖度分析
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存覆盖度分析
     */
    @RequiresPermissions("stat:cover:add")
    @Log(title = "覆盖度分析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatDataCover statDataCover)
    {
        return toAjax(statDataCoverService.insertStatDataCover(statDataCover));
    }

    /**
     * 修改覆盖度分析
     */
    @GetMapping("/edit/{coverId}")
    public String edit(@PathVariable("coverId") Long coverId, ModelMap mmap)
    {
        StatDataCover statDataCover = statDataCoverService.selectStatDataCoverById(coverId);
        mmap.put("statDataCover", statDataCover);
        return prefix + "/edit";
    }

    /**
     * 修改保存覆盖度分析
     */
    @RequiresPermissions("stat:cover:edit")
    @Log(title = "覆盖度分析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatDataCover statDataCover)
    {
        return toAjax(statDataCoverService.updateStatDataCover(statDataCover));
    }

    /**
     * 删除覆盖度分析
     */
    @RequiresPermissions("stat:cover:remove")
    @Log(title = "覆盖度分析", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statDataCoverService.deleteStatDataCoverByIds(ids));
    }
    
    @RequiresPermissions("stat:cover:showCoverDetailPage")
  	@GetMapping("/showCoverDetailPage/{coverId}")
  	public String showCoverDetailPage(@PathVariable("coverId") Long coverId, ModelMap mmap) {
  		mmap.put("coverId", coverId);
  		return prefix + "/cover-detail-table-list";
  	}
}
